import Mock from 'mockjs'

Mock.mock('/api/login', 'post', (options) => {
  const postData = JSON.parse(options.body)
  const compareData = JSON.parse(localStorage.getItem('user'))
  if (postData.username != compareData.username) {
    return { status: 400, message: '用户名错误！' }
  }
  if (postData.password != compareData.password) {
    return { status: 400, message: '密码错误！' }
  }
  return { status: 200, message: 'OK' }
})

Mock.Random.extend({
  dorm: function () {
    const dormList = ['一善书院', '双馨书院', '三创书院', '四实书院', '八方书院', '拾德书院']
    return this.pick(dormList)
  },
})

Mock.mock('/api/students', 'get', {
  'data|10': [
    {
      id: '@id',
      name: '@cname',
      dorm: '@dorm',
      'score|1-100': 1,
    },
  ],
})

Mock.mock(/\/api\/students\/\d+/, 'delete', {
  status: 200,
  message: '删除成功',
})

Mock.mock('/api/students', 'put', {
  status: 200,
  message: '修改成功',
})
